using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using FitnessClub.Bll.AccountManager;

public partial class TicketManager : System.Web.UI.Page
{
    #region Page_Load
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
        }

		RadioButtonRodzajKarnetuChanged();
		RefreshSheet();
    } 
    #endregion


	protected void RefreshSheet()
	{
		LabelPointsTicket_Price.Text = AppSettings.PointsTicket_Price.ToString();
		LabelDaysTicketLimited_Price.Text = AppSettings.DaysTicketLimited_Price.ToString();
		LabelDaysTicketUnlimited_Price.Text = AppSettings.DaysTicketUnlimited_Price.ToString();

		int PointsTicket_TotalPrice = int.Parse(TextBoxLiczbaPunktow.Text) * AppSettings.PointsTicket_Price;
		int DaysTicketLimited_TotalPrice = int.Parse(TextBoxLiczbaDniZwykly.Text) * AppSettings.DaysTicketLimited_Price;
		int DaysTicketUnlimited_TotalPrice = int.Parse(TextBoxLiczbaDniRozszezony.Text) * AppSettings.DaysTicketUnlimited_Price;

		LabelPointsTicket_TotalPrice.Text = PointsTicket_TotalPrice.ToString();
		LabelDaysTicketLimited_TotalPrice.Text = DaysTicketLimited_TotalPrice.ToString();
		LabelDaysTicketUnlimited_TotalPrice.Text = DaysTicketUnlimited_TotalPrice.ToString();

		TotalPrice.Text = (PointsTicket_TotalPrice + DaysTicketLimited_TotalPrice + DaysTicketUnlimited_TotalPrice).ToString();  
	}


	protected void RadioButtonRodzajKarnetuChanged(object sender, EventArgs e)
	{
		if (RadioButtonKarnetRozszezony.Checked == true && RadioButtonKarnetZwykly.Checked == false)
		{
			TextBoxLiczbaDniRozszezony.Enabled = true;
			TextBoxLiczbaDniZwykly.Enabled = false;
			TextBoxLiczbaDniZwykly.Text = "0";
		}
		else if (RadioButtonKarnetRozszezony.Checked == false && RadioButtonKarnetZwykly.Checked == true)
		{
			TextBoxLiczbaDniRozszezony.Enabled = false;
			TextBoxLiczbaDniRozszezony.Text = "0";
			TextBoxLiczbaDniZwykly.Enabled = true;
		}
	}

	protected void RadioButtonRodzajKarnetuChanged()
	{
		if (RadioButtonKarnetRozszezony.Checked == true && RadioButtonKarnetZwykly.Checked == false)
		{
			TextBoxLiczbaDniRozszezony.Enabled = true;
			TextBoxLiczbaDniZwykly.Enabled = false;
			TextBoxLiczbaDniZwykly.Text = "0";
		}
		else if (RadioButtonKarnetRozszezony.Checked == false && RadioButtonKarnetZwykly.Checked == true)
		{
			TextBoxLiczbaDniRozszezony.Enabled = false;
			TextBoxLiczbaDniRozszezony.Text = "0";
			TextBoxLiczbaDniZwykly.Enabled = true;
		}
	}


	protected void AddUser_Click(object sender, EventArgs e)
	{
		if (Delegate.IsUserExisting(TextBoxLogin.Text) == false) 
			throw new Exception("W bazie niema usera o danym loginie:" + TextBoxLogin.Text);

		Delegate.ticketFeeding(TextBoxLogin.Text, int.Parse(TextBoxLiczbaPunktow.Text), /*PointsTicket =*/ 0);
		Delegate.ticketFeeding(TextBoxLogin.Text, int.Parse(TextBoxLiczbaDniZwykly.Text), /*DaysTicketLimited =*/ 1);
		Delegate.ticketFeeding(TextBoxLogin.Text, int.Parse(TextBoxLiczbaDniRozszezony.Text), /*DaysTicketUnlimited =*/ 2);



		StateManager.Instance.AddToSession(SessionKeys.TicketsSummaryLogin, TextBoxLogin.Text);
		Response.Redirect("ticketsSummary.aspx");
	}

	protected void Cancel_Click(object sender, EventArgs e)
	{
		Response.Redirect("Recepcjonista.aspx");
	}
}
